package tcards.android;

import models.Tcard;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class GeneralFieldList extends LinearLayout {
	private TextField   mSTUnit;
	private TextField   mName;
	private DateField   mCheckedIn;
	private TextField   mHomeBase;
	private TextField   mDeparturePoint;
	private TextField   mETD;
	private TextField   mETA;
	private DateField   mOrdered;
	private MultiField  mRemarks;
	
	public GeneralFieldList(Context context) {
		this(context, null, 0);
	}

	public GeneralFieldList(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public GeneralFieldList(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.general_field_list, this, false));
		
		mSTUnit         = (TextField)   findViewById(R.id.stUnitField);
		mName           = (TextField)   findViewById(R.id.nameField);
		mCheckedIn      = (DateField)   findViewById(R.id.dateCheckedInField);
		mHomeBase       = (TextField)   findViewById(R.id.homeBaseField);
		mDeparturePoint = (TextField)   findViewById(R.id.departurePointField);
		mETD            = (TextField)   findViewById(R.id.etdField);
		mETA            = (TextField)   findViewById(R.id.etaField);
		mOrdered        = (DateField)   findViewById(R.id.dateOrderedField);
		mRemarks        = (MultiField)  findViewById(R.id.remarksField);
	}
	
	public void setTcardFields(Tcard tcard) {
		tcard.setSt_Unit(mSTUnit.getTextValue());
		tcard.setDisplayId(mName.getTextValue());
		tcard.setCheckedIn(mCheckedIn.getDateValue());
		tcard.setHomeBase(mHomeBase.getTextValue());
		tcard.setDeparturePoint(mDeparturePoint.getTextValue());
		tcard.setETD(mETD.getTextValue());
		tcard.setETA(mETA.getTextValue());
		tcard.setOrdered(mOrdered.getDateValue());
		tcard.setRemarks(mRemarks.getTextValue());
	}
	
	public void setListFields(Tcard tcard) {
		mSTUnit.setTextValue(tcard.getSt_Unit());
		mName.setTextValue(tcard.getDisplayId());
		mCheckedIn.setDateValue(tcard.getCheckedIn());
		mHomeBase.setTextValue(tcard.getHomeBase());
		mDeparturePoint.setTextValue(tcard.getDeparturePoint());
		mETD.setTextValue(tcard.getETD());
		mETA.setTextValue(tcard.getETA());
		mOrdered.setDateValue(tcard.getOrdered());
		mRemarks.setTextValue(tcard.getRemarks());
	}
	
	public TextField getSTUnit() {
		return mSTUnit;
	}
	
	public TextField getName() {
		return mName;
	}
	
	public DateField getCheckedIn() {
		return mCheckedIn;
	}
	
	public TextField getHomeBase() {
		return mHomeBase;
	}
	
	public TextField getDeparturePoint() {
		return mDeparturePoint;
	}
	
	public TextField getETD() {
		return mETD;
	}
	
	public TextField getETA() {
		return mETA;
	}
	
	public DateField getOrdered() {
		return mOrdered;
	}
	
	public MultiField getRemarks() {
		return mRemarks;
	}
}